package com.iplant.wms.service.po.hr;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.po.DBBasePO;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.wms.service.basicenum.wms.WMSStockAlarmStatus;

import java.io.Serializable;
import java.util.Calendar;

/**
 * 库存预警
 *
 * @author ShrisJava
 */
@DBBasePO(TableName = "wms_stock_alarm_item", Name = false, Active = false, CheckName = {
        "Code", "StockAlarmID,MaterialID", "StockAlarmCode,MaterialID"},
        Schemas = DBSchemas.WMS, CodeAuto = true, CodePrefix = "{:StockAlarmCode}", CodeNum = 3)
public class WMSStockAlarmItemHR extends BasePO implements Serializable {
    private static final long serialVersionUID = 1L;


    @DBCondition
    @DBField(CheckValue = true, Update = false)
    public int StockAlarmID = 0;

    @DBCondition
    @DBField(CheckValue = true, Update = false)
    public String StockAlarmCode = "";


    @DBCondition
    @DBField(Update = false)
    public int FactoryID = 0;

    @DBJoin(name = "Code", tableName = "fmc_factory", tableAsName = "f1",
            Schemas = DBSchemas.Basic, MainTableField = "FactoryID")
    public String FactoryCode = "";

    @DBJoin(name = "Name", tableName = "fmc_factory", tableAsName = "f1",
            Schemas = DBSchemas.Basic, MainTableField = "FactoryID")
    public String FactoryName = "";

    @DBCondition
    @DBField(Update = false)
    public int OrderID = 0;

    @DBCondition
    @DBField(Update = false)
    public String OrderNo = "";


    @DBCondition
    @DBField
    public int StoreID = 0;

    @DBJoin(name = "Name", tableName = "wms_store", tableAsName = "s4",
            JoinMode = DBJoin.DBJoinMode.Left,
            Schemas = DBSchemas.WMS, MainTableField = "StoreID")
    public String StoreName = "";
    @DBJoin(name = "Code", tableName = "wms_store", tableAsName = "s4",
            JoinMode = DBJoin.DBJoinMode.Left,
            Schemas = DBSchemas.WMS, MainTableField = "StoreID")
    public String StoreCode = "";


    @DBCondition
    @DBJoin(name = "MaterialGroupID", tableName = "mss_material", tableAsName = "m2",
            JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, MainTableField = "MaterialID")
    public int MaterialGroupID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "mss_materialgroup", tableAsName = "m1",
            JoinIndex = 3, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialGroupID=m1.ID")
    public String MaterialGroupCode = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "mss_materialgroup", tableAsName = "m1",
            JoinIndex = 3, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialGroupID=m1.ID")
    public String MaterialGroupName = "";


    @DBCondition(CompareType = DBCondition.DBCompareType.leftLike)
    @DBJoin(name = "FullGroupName", tableName = "mss_materialgroup", tableAsName = "m1",
            JoinIndex = 3, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialGroupID=m1.ID")
    public String MaterialFullGroup = "";

    @DBCondition
    @DBField(CheckValue = true)
    public int MaterialID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "mss_material", tableAsName = "m2", JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, MainTableField = "MaterialID")
    public String MaterialCode = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "mss_material", tableAsName = "m2", JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, MainTableField = "MaterialID")
    public String MaterialName = "";


    /**
     * 辅计量单位ID
     */
    @DBField
    public int UnitID = 0;
    /**
     * 辅计量单位
     */
    @DBJoin(name = "Name", tableName = "mss_unit", tableAsName = "unt1", Schemas = DBSchemas.Basic,
            MainTableField = "UnitID")
    public String UnitText = "";

    @DBJoin(name = "Code", tableName = "mss_unit", tableAsName = "unt1", Schemas = DBSchemas.Basic,
            MainTableField = "UnitID")
    public String UnitCode = "";

    /**
     * 预警日期
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.geLe, ParamName = "AlarmDateStart", ParamName2 = "AlarmDateEnd")
    @DBField(Update = false)
    public Calendar AlarmDate = Calendar.getInstance();

    /**
     * 需求数
     */
    @DBField
    public double NeedFQTY = 0;

    /**
     * 缺少数
     */
    @DBField
    public double ShortFQTY = 0;


    public double DeliveryFQTY = 0;


    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int Status = 0;

    public String StatusText = "";


    public WMSStockAlarmItemHR() {
    }


    public WMSStockAlarmItemHR(WMSStockAlarmHR wStockAlarmHR, double wNeedFQTY) {
        StockAlarmID = wStockAlarmHR.ID;
        StockAlarmCode = wStockAlarmHR.Code;
        FactoryID = wStockAlarmHR.FactoryID;
        FactoryCode = wStockAlarmHR.FactoryCode;
        FactoryName = wStockAlarmHR.FactoryName;
        OrderID = wStockAlarmHR.OrderID;
        OrderNo = wStockAlarmHR.OrderNo;
        StoreID = wStockAlarmHR.StoreID;
        StoreCode = wStockAlarmHR.StoreCode;
        StoreName = wStockAlarmHR.StoreName;
        AlarmDate = wStockAlarmHR.AlarmDate;


        NeedFQTY = wNeedFQTY;

    }


    @JsonProperty("StockAlarmID")
    public int getStockAlarmID() {
        return StockAlarmID;
    }

    public void setStockAlarmID(int stockAlarmID) {
        StockAlarmID = stockAlarmID;
    }

    @JsonProperty("StockAlarmCode")
    public String getStockAlarmCode() {
        return StockAlarmCode;
    }

    public void setStockAlarmCode(String stockAlarmCode) {
        StockAlarmCode = stockAlarmCode;
    }

    @JsonProperty("FactoryID")
    public int getFactoryID() {
        return FactoryID;
    }

    public void setFactoryID(int factoryID) {
        FactoryID = factoryID;
    }

    @JsonProperty("FactoryCode")
    public String getFactoryCode() {
        return FactoryCode;
    }

    public void setFactoryCode(String factoryCode) {
        FactoryCode = factoryCode;
    }

    @JsonProperty("FactoryName")
    public String getFactoryName() {
        return FactoryName;
    }

    public void setFactoryName(String factoryName) {
        FactoryName = factoryName;
    }

    @JsonProperty("OrderID")
    public int getOrderID() {
        return OrderID;
    }

    public void setOrderID(int orderID) {
        OrderID = orderID;
    }

    @JsonProperty("OrderNo")
    public String getOrderNo() {
        return OrderNo;
    }

    public void setOrderNo(String orderNo) {
        OrderNo = orderNo;
    }

    @JsonProperty("StoreID")
    public int getStoreID() {
        return StoreID;
    }

    public void setStoreID(int storeID) {
        StoreID = storeID;
    }

    @JsonProperty("StoreName")
    public String getStoreName() {
        return StoreName;
    }

    public void setStoreName(String storeName) {
        StoreName = storeName;
    }

    @JsonProperty("StoreCode")
    public String getStoreCode() {
        return StoreCode;
    }

    public void setStoreCode(String storeCode) {
        StoreCode = storeCode;
    }

    @JsonProperty("MaterialGroupID")
    public int getMaterialGroupID() {
        return MaterialGroupID;
    }

    public void setMaterialGroupID(int materialGroupID) {
        MaterialGroupID = materialGroupID;
    }

    @JsonProperty("MaterialGroupCode")
    public String getMaterialGroupCode() {
        return MaterialGroupCode;
    }

    public void setMaterialGroupCode(String materialGroupCode) {
        MaterialGroupCode = materialGroupCode;
    }

    @JsonProperty("MaterialGroupName")
    public String getMaterialGroupName() {
        return MaterialGroupName;
    }

    public void setMaterialGroupName(String materialGroupName) {
        MaterialGroupName = materialGroupName;
    }

    @JsonProperty("MaterialFullGroup")
    public String getMaterialFullGroup() {
        return MaterialFullGroup;
    }

    public void setMaterialFullGroup(String materialFullGroup) {
        MaterialFullGroup = materialFullGroup;
    }

    @JsonProperty("MaterialID")
    public int getMaterialID() {
        return MaterialID;
    }

    public void setMaterialID(int materialID) {
        MaterialID = materialID;
    }

    @JsonProperty("MaterialCode")
    public String getMaterialCode() {
        return MaterialCode;
    }

    public void setMaterialCode(String materialCode) {
        MaterialCode = materialCode;
    }

    @JsonProperty("MaterialName")
    public String getMaterialName() {
        return MaterialName;
    }

    public void setMaterialName(String materialName) {
        MaterialName = materialName;
    }

    @JsonProperty("AlarmDate")
    public Calendar getAlarmDate() {
        return AlarmDate;
    }

    public void setAlarmDate(Calendar alarmDate) {
        AlarmDate = alarmDate;
    }

    @JsonProperty("Status")
    public int getStatus() {
        return Status;
    }

    public void setStatus(int status) {
        Status = status;
    }

    @JsonProperty("StatusText")
    public String getStatusText() {

        StatusText = WMSStockAlarmStatus.getEnumType(Status).getLabel();
        return StatusText;
    }

    public void setStatusText(String statusText) {
        StatusText = statusText;
    }

    @JsonProperty("NeedFQTY")
    public double getNeedFQTY() {
        return NeedFQTY;
    }

    public void setNeedFQTY(double needFQTY) {
        NeedFQTY = needFQTY;
    }

    @JsonProperty("ShortFQTY")
    public double getShortFQTY() {
        return ShortFQTY;
    }

    public void setShortFQTY(double shortFQTY) {
        ShortFQTY = shortFQTY;
    }

    @JsonProperty("DeliveryFQTY")
    public double getDeliveryFQTY() {
        DeliveryFQTY = NeedFQTY - ShortFQTY;
        return DeliveryFQTY;
    }

    public void setDeliveryFQTY(double deliveryFQTY) {
        DeliveryFQTY = deliveryFQTY;
    }

    @JsonProperty("UnitID")
    public int getUnitID() {
        return UnitID;
    }

    public void setUnitID(int unitID) {
        UnitID = unitID;
    }

    @JsonProperty("UnitText")
    public String getUnitText() {
        return UnitText;
    }

    public void setUnitText(String unitText) {
        UnitText = unitText;
    }

    @JsonProperty("UnitCode")
    public String getUnitCode() {
        return UnitCode;
    }

    public void setUnitCode(String unitCode) {
        UnitCode = unitCode;
    }
}
